using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using DBSourceToolsLib;
using DBConnectionLib;


namespace TestDBSourceToolsLibNUnit
{
    [TestFixture]    
    public class TestDatabaseExClass
    {
        [TestFixtureSetUp]
        public void TestFixtureSetup()
        {
            FileHelper oFileHelper = new FileHelper();
            oFileHelper.DeleteFilesInDir(Constants.TestFiles_Output_CreateScripts_Dir);
        }


        [Test]
        public void TestScriptDatabase()
        {
            DatabaseEx oDatabaseEx = new DatabaseEx(
                new Database("TestCreateScript", ".", "AdventureWorks_1.1", 
                    Constants.TestFiles_Output_CreateScripts_Dir), false
                );
            oDatabaseEx.AddDropAndCreateScript(
                new DatabaseEx(
                Constants.AdventureWorksLT_Database, true));

            string strCreateScriptName = Constants.TestFiles_Output_CreateScripts_Dir + "AdventureWorks_1.1_CreateDB.sql";
            string strDropScriptName = Constants.TestFiles_Output_CreateScripts_Dir + "AdventureWorks_1.1_DropDB.sql";
            Assert.IsTrue(System.IO.File.Exists( strCreateScriptName  ), "cannot find " + strCreateScriptName);
            Assert.IsTrue(System.IO.File.Exists(strDropScriptName), "cannot find " + strDropScriptName);


            string strCreateScriptControl = Constants.TestFiles_Control_CreateScripts_Dir + "AdventureWorks_1.1_CreateDB.sql";
            string strDropScriptControl = Constants.TestFiles_Control_CreateScripts_Dir + "AdventureWorks_1.1_DropDB.sql";

            FileHelper oFileHelper = new FileHelper();
            oFileHelper.CompareFiles(strCreateScriptControl, strCreateScriptName);
            //FileAssert.AreEqual(strCreateScriptControl, strCreateScriptName);

        }

        [Test]
        public void TestVerifyScriptFile()
        {
            DatabaseEx oDatabaseEx = new DatabaseEx(
                new Database("TestCreateScript", ".", "AdventureWorks_1.1",
                    Constants.TestFiles_Output_CreateScripts_Dir), false
                );
            oDatabaseEx.AddDropAndCreateScript(
                new DatabaseEx(
                Constants.AdventureWorksLT_Database, true));

            string strCreateScriptControl = Constants.TestFiles_Control_CreateScripts_Dir + "AdventureWorks_1.1_CreateDB.sql";
            Assert.IsTrue(oDatabaseEx.VerifyCreateScript(strCreateScriptControl), strCreateScriptControl + " should not be valid");

        }


        [Test]
        public void TestVerifyScriptFileBothInvalid()
        {
            DatabaseEx oDatabaseEx = new DatabaseEx(
                new Database("TestCreateScript", ".", "AdventureWorks_1.1",
                    Constants.TestFiles_Output_CreateScripts_Dir), false
                );
            oDatabaseEx.AddDropAndCreateScript(
                new DatabaseEx(
                Constants.AdventureWorksLT_Database, true));

            string strCreateScriptControl = Constants.TestFiles_Control_CreateScripts_Dir + "AdventureWorks_1.1_CreateDBInvalid.sql";
            Assert.IsFalse(oDatabaseEx.VerifyCreateScript(strCreateScriptControl), strCreateScriptControl + " should not be valid");

        }

        [Test]
        public void TestVerifyScriptFileFirstInvalid()
        {
            DatabaseEx oDatabaseEx = new DatabaseEx(
                new Database("TestCreateScript", ".", "AdventureWorks_1.1",
                    Constants.TestFiles_Output_CreateScripts_Dir), false
                );
            oDatabaseEx.AddDropAndCreateScript(
                new DatabaseEx(
                Constants.AdventureWorksLT_Database, true));

            string strCreateScriptControl = Constants.TestFiles_Control_CreateScripts_Dir + "AdventureWorks_1.1_CreateDBInvalid_First.sql";
            Assert.IsFalse(oDatabaseEx.VerifyCreateScript(strCreateScriptControl), strCreateScriptControl + " should not be valid");

        }

        [Test]
        public void TestVerifyScriptFileSecondInvalid()
        {
            DatabaseEx oDatabaseEx = new DatabaseEx(
                new Database("TestCreateScript", ".", "AdventureWorks_1.1",
                    Constants.TestFiles_Output_CreateScripts_Dir), false
                );
            oDatabaseEx.AddDropAndCreateScript(
                new DatabaseEx(
                Constants.AdventureWorksLT_Database, true));

            string strCreateScriptControl = Constants.TestFiles_Control_CreateScripts_Dir + "AdventureWorks_1.1_CreateDBInvalid_Second.sql";
            Assert.IsFalse(oDatabaseEx.VerifyCreateScript(strCreateScriptControl), strCreateScriptControl + " should not be valid");

        }


    }
}
